package com.nondo.rdp.finance.endpoint.api.app.course;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nondo.rdp.core.model.View;
import com.nondo.rdp.finance.domain.setting.advert.Advert;
import com.nondo.rdp.finance.model.course.AppStageCourseQuery;
import com.nondo.rdp.finance.service.course.StageCourseService;
import com.nondo.rdp.finance.service.setting.advert.AdvertService;

@RestController("apiAppStageCourse")
@RequestMapping("/api/app/stageCourse")
public class StageCourseEndpoint {
    @Autowired
    StageCourseService stageCourseService;
    
    @Autowired
    AdvertService advertService;
    
    
    
    /**
     * 获取阶段课程列表
     * @param request
     * @param response
     * @param query
     * @return
     */
    @RequestMapping("/list/{value}")
    public View<Map<String,Object>> list(HttpServletRequest request, HttpServletResponse response, @PathVariable("value") Integer type) {
        View<Map<String,Object>> view = new View<Map<String,Object>>(20000, "获取列表成功");

        Map<String,Object> resultMap = new HashMap<String, Object>();
        
        List<Advert> advertList = advertService.findAll(1);
        if (advertList == null) {
        	advertList = new ArrayList<Advert>();
        }
        resultMap.put("ad", advertList);
        
        List<AppStageCourseQuery>  stageCourseQueryList = stageCourseService.findAll(type);
        if (stageCourseQueryList == null ) {
        	stageCourseQueryList = new ArrayList<AppStageCourseQuery>();
        }
        resultMap.put("content", stageCourseQueryList);

        view.setData(resultMap);

        return view;
    }
    
    /**
     * 获取引导列表
     * @param request
     * @param response
     * @param query
     * @return
     */
    @RequestMapping("/guideList")
    public View<List<Advert> > guideList(HttpServletRequest request, HttpServletResponse response) {
        View<List<Advert> > view = new View<List<Advert> >(20000, "获取列表成功");

        List<Advert> advertList = advertService.findAll(0);
        if (advertList == null) {
        	advertList = new ArrayList<Advert>();
        }
        view.setData(advertList);

        return view;
    }
}